package com.qdxwx.quartz.controller;

import com.qdxwx.common.annotation.Permissions;
import com.qdxwx.common.json.AjaxResult;
import com.qdxwx.common.page.PageRequest;
import com.qdxwx.common.page.TableDataInfo;
import com.qdxwx.quartz.domain.Job;
import com.qdxwx.quartz.domain.JobLog;
import com.qdxwx.quartz.service.JobLogService;
import com.qdxwx.quartz.service.JobService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调度日志操作处理
 * 
 * @author qdxwx
 */
@Controller
@RequestMapping("/monitor/jobLog")
public class JobLogController {
    private String prefix = "monitor/job";

    @Autowired
    private JobService jobService;

    @Autowired
    private JobLogService jobLogService;

    @Permissions("monitor:job:list")
    @GetMapping("/list.html")
    public String jobLog(@RequestParam(value = "jobId", required = false) Long jobId, ModelMap mmap) {
        if ((null != jobId)) {
            Job job = jobService.selectJobById(jobId);
            mmap.put("job", job);
        }
        return prefix + "/jobLog";
    }

    @Permissions("monitor:job:list")
    @PostMapping("/list.json")
    @ResponseBody
    public TableDataInfo list(HttpServletRequest request, JobLog jobLog) {
        List<JobLog> list = jobLogService.getList(jobLog, PageRequest.form(request));
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(jobLogService.count(jobLog));
        return rspData;
    }

    //@Log(title = "调度日志", businessType = BusinessType.DELETE)
    @Permissions("monitor:job:remove")
    @PostMapping("/remove.json")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return AjaxResult.success(jobLogService.deleteJobLogByIds(ids));
    }

    @Permissions("monitor:job:detail")
    @GetMapping("/detail/{jobLogId}")
    public String detail(@PathVariable("jobLogId") Long jobLogId, ModelMap mmap) {
        mmap.put("name", "jobLog");
        mmap.put("jobLog", jobLogService.selectJobLogById(jobLogId));
        return prefix + "/detail";
    }

}
